package com.jeecg.p3.system.poster.service;

import com.jeecg.p3.system.poster.dao.PosterManagerDao;
import com.jeecg.p3.system.poster.dao.WhitePersonDao;
import com.jeecg.p3.system.poster.entity.PosterManager;
import com.jeecg.p3.system.poster.entity.WhitePerson;
import org.jeecgframework.p3.core.utils.common.PageList;
import org.jeecgframework.p3.core.utils.common.PageQuery;
import org.jeecgframework.p3.core.utils.common.PageQueryWrapper;
import org.jeecgframework.p3.core.utils.common.Pagenation;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 *
 * @ClassName: WhitePersonService
 * @Description: TODO 白名单处理层
 * @author: zhangxiao
 * @date: 2020年11月30日 下午7:29:38
 */
@Service
public class WhitePersonService {
    @Resource
    private WhitePersonDao dao;

    /**
     * 分页查询白名单
     * @param pageQuery
     * @return
     */
    public PageList<WhitePerson> queryPageList(PageQuery<WhitePerson> pageQuery) {
        PageList<WhitePerson> result = new PageList<WhitePerson>();
        Integer itemCount = dao.count(pageQuery);
        PageQueryWrapper<WhitePerson> wrapper = new PageQueryWrapper<WhitePerson>(pageQuery.getPageNo(), pageQuery.getPageSize(),itemCount, pageQuery.getQuery());
        List<WhitePerson> list = dao.queryPageList(wrapper);
        Pagenation pagenation = new Pagenation(pageQuery.getPageNo(), itemCount, pageQuery.getPageSize());
        result.setPagenation(pagenation);
        result.setValues(list);
        return result;
    }

    /**
     * 根据传参获取白名单数量
     * @param whitePerson
     * @return
     */
    public Integer count(WhitePerson whitePerson) {
        PageQuery<WhitePerson> pageQuery = new PageQuery<>();
        pageQuery.setQuery(whitePerson);
        return dao.count(pageQuery);
    }

    /**
     * 新增白名单信息
     * @param whitePerson
     */
    public void doAdd(WhitePerson whitePerson) {
        dao.insert(whitePerson);
    }

    /**
     * 根据id查询白名单信息
     * @param id
     * @return
     */
    public WhitePerson findById(Long id) {
        return dao.get(id);
    }

    /**
     * 根据传参获取白名单列表信息
     * @param whitePerson
     * @return
     */
    public List<WhitePerson> findByParam(WhitePerson whitePerson) {
        if(whitePerson == null) {
            whitePerson = new WhitePerson();
        }
        return dao.findByParam(whitePerson);
    }

    /**
     * 编辑白名单信息
     * @param whitePerson
     */
    public void doEdit(WhitePerson whitePerson) {
        dao.update(whitePerson);
    }

    /**
     * 删除白名单信息
     * @param whitePerson
     */
    public void doDelete(WhitePerson whitePerson) {
        whitePerson.setStatus("0");
        dao.update(whitePerson);
    }
}
